
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加密货币技术分析工具</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#36CFC9',
                        success: '#52C41A',
                        warning: '#FAAD14',
                        danger: '#FF4D4F',
                        dark: '#1D2129',
                        'dark-2': '#4E5969',
                        'light-1': '#F2F3F5',
                        'light-2': '#E5E6EB'
                    },
                    fontFamily: {
                        inter: ['Inter', 'system-ui', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .card-shadow {
                box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            }
            .analysis-card {
                transition: transform 0.3s ease, box-shadow 0.3s ease;
            }
            .analysis-card:hover {
                transform: translateY(-5px);
                box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
            }
            .gradient-bg {
                background: linear-gradient(135deg, #165DFF 0%, #36CFC9 100%);
            }
        }
    </style>
</head>
<body class="bg-gray-50 font-inter text-dark">
    <div class="min-h-screen flex flex-col">
        <!-- 头部 -->
        <header class="gradient-bg text-white py-6 px-4 md:px-8">
            <div class="container mx-auto">
                <h1 class="text-[clamp(1.5rem,3vw,2.5rem)] font-bold flex items-center">
                    <i class="fa fa-line-chart mr-3"></i>加密货币技术分析工具
                </h1>
                <p class="mt-2 text-white/80">快速分析BTC和ETH的市场趋势与关键指标</p>
            </div>
        </header>

        <!-- 主要内容 -->
        <main class="flex-grow container mx-auto py-8 px-4 md:px-8">
            <!-- 分析控制区 -->
            <div class="bg-white rounded-lg p-6 mb-8 card-shadow">
                <div class="flex flex-col md:flex-row justify-between items-center">
                    <div>
                        <h2 class="text-xl font-semibold mb-2">市场分析</h2>
                        <p class="text-dark-2">将同时分析 10分钟、30分钟和60分钟 三个周期的技术指标</p>
                    </div>
                    <button id="start-analysis" onclick="startAnalysis()"
                            class="mt-4 md:mt-0 bg-primary hover:bg-primary/90 text-white font-medium py-2 px-6 rounded-lg transition-all flex items-center">
                        <i class="fa fa-play-circle mr-2"></i>开始分析
                    </button>
                </div>

                <div id="status" class="hidden mt-4 p-3 bg-light-1 rounded-lg flex items-center text-dark-2">
                    <i class="fa fa-spinner fa-spin mr-2"></i>正在获取数据并分析，请稍候...
                </div>
            </div>

            <!-- 分析结果区域 -->
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <!-- BTC分析结果卡片将通过JS动态生成 -->
                <div id="btc-container" class="space-y-6"></div>

                <!-- ETH分析结果卡片将通过JS动态生成 -->
                <div id="eth-container" class="space-y-6"></div>
            </div>
        </main>

        <!-- 页脚 -->
        <footer class="bg-dark text-white/70 py-4 px-4 md:px-8">
            <div class="container mx-auto text-center text-sm">
                <p>数据仅供参考，不构成投资建议 | 技术指标基于历史数据计算</p>
            </div>
        </footer>
    </div>

    <script>
        // 技术指标计算函数 - 保留核心
        function calculateRSI(data, period) {
            if (data.length < period + 1) {
                return Array(data.length).fill(null);
            }

            const rsi = Array(period).fill(null);
            let avgGain = 0;
            let avgLoss = 0;

            // 计算初始平均值
            for (let i = 1; i <= period; i++) {
                const change = data[i].close - data[i - 1].close;
                if (change > 0) {
                    avgGain += change;
                } else {
                    avgLoss += Math.abs(change);
                }
            }

            avgGain /= period;
            avgLoss /= period;

            // 计算第一个RSI值
            const rs = avgLoss === 0 ? 100 : avgGain / avgLoss;
            rsi.push(100 - (100 / (1 + rs)));

            // 计算后续RSI值
            for (let i = period + 1; i < data.length; i++) {
                const change = data[i].close - data[i - 1].close;
                let gain = 0;
                let loss = 0;

                if (change > 0) {
                    gain = change;
                    loss = 0;
                } else {
                    gain = 0;
                    loss = Math.abs(change);
                }

                // 平滑计算平均值
                avgGain = (avgGain * (period - 1) + gain) / period;
                avgLoss = (avgLoss * (period - 1) + loss) / period;

                const rs = avgLoss === 0 ? 100 : avgGain / avgLoss;
                rsi.push(100 - (100 / (1 + rs)));
            }

            return rsi;
        }

        function calculateMACD(data, shortPeriod = 12, longPeriod = 26, signalPeriod = 9) {
            if (data.length < longPeriod + signalPeriod) {
                return {
                    dif: Array(data.length).fill(null),
                    dea: Array(data.length).fill(null),
                    macd: Array(data.length).fill(null)
                };
            }

            // 计算短期EMA和长期EMA
            const shortEMA = calculateEMA(data, shortPeriod);
            const longEMA = calculateEMA(data, longPeriod);

            // 计算DIF
            const dif = shortEMA.map((val, i) => val !== null && longEMA[i] !== null ? val - longEMA[i] : null);

            // 计算DEA (DIF的signalPeriod日EMA)
            const dea = calculateEMA(dif.map((val, i) => ({ close: val || 0, time: data[i]?.time || 0 })), signalPeriod);

            // 计算MACD柱状图 (DIF-DEA)*2
            const macd = dif.map((val, i) => val !== null && dea[i] !== null ? (val - dea[i]) * 2 : null);

            return { dif, dea, macd };
        }

        function calculateEMA(data, period) {
            const ema = Array(period - 1).fill(null);
            if (data.length < period) return ema;

            // 计算SMA作为初始值
            let sum = 0;
            for (let i = 0; i < period; i++) {
                sum += data[i].close;
            }
            ema.push(sum / period);

            // 计算后续EMA值
            const multiplier = 2 / (period + 1);
            for (let i = period; i < data.length; i++) {
                ema.push((data[i].close - ema[i - 1]) * multiplier + ema[i - 1]);
            }

            return ema;
        }

        function calculateKDJ(data, period = 9, kPeriod = 3, dPeriod = 3) {
            if (data.length < period + dPeriod) {
                return {
                    k: Array(data.length).fill(null),
                    d: Array(data.length).fill(null),
                    j: Array(data.length).fill(null)
                };
            }

            const kValues = [];
            const dValues = [];
            const jValues = [];

            // 计算RSV值
            for (let i = 0; i < data.length; i++) {
                if (i < period - 1) {
                    kValues.push(null);
                    dValues.push(null);
                    jValues.push(null);
                    continue;
                }

                // 找出period日内的最高价和最低价
                let high = -Infinity;
                let low = Infinity;
                for (let j = i - period + 1; j <= i; j++) {
                    high = Math.max(high, data[j].high);
                    low = Math.min(low, data[j].low);
                }

                const close = data[i].close;
                const rsv = (close - low) / (high - low) * 100;

                // 计算K值 (RSV的kPeriod日平滑)
                let k = rsv;
                if (kValues[i - 1] !== null) {
                    k = (kValues[i - 1] * (kPeriod - 1) + rsv) / kPeriod;
                }
                kValues.push(k);

                // 计算D值 (K值的dPeriod日平滑)
                let d = k;
                if (dValues[i - 1] !== null) {
                    d = (dValues[i - 1] * (dPeriod - 1) + k) / dPeriod;
                }
                dValues.push(d);

                // 计算J值
                jValues.push(3 * k - 2 * d);
            }

            return { k: kValues, d: dValues, j: jValues };
        }

        function calculateBollingerBands(data, period = 20, multiplier = 2) {
            if (data.length < period) {
                return {
                    upper: Array(data.length).fill(null),
                    middle: Array(data.length).fill(null),
                    lower: Array(data.length).fill(null)
                };
            }

            const middle = calculateMA(data, period);
            const upper = [];
            const lower = [];

            // 计算标准差
            for (let i = 0; i < data.length; i++) {
                if (i < period - 1) {
                    upper.push(null);
                    lower.push(null);
                    continue;
                }

                // 计算标准差
                let sum = 0;
                for (let j = i - period + 1; j <= i; j++) {
                    sum += Math.pow(data[j].close - middle[i], 2);
                }
                const stdDev = Math.sqrt(sum / period);

                // 计算上下轨
                upper.push(middle[i] + multiplier * stdDev);
                lower.push(middle[i] - multiplier * stdDev);
            }

            return { upper, middle, lower };
        }

        function calculateMA(data, period) {
            const ma = [];
            for (let i = 0; i < data.length; i++) {
                if (i < period - 1) {
                    ma.push(null);
                    continue;
                }

                let sum = 0;
                for (let j = i - period + 1; j <= i; j++) {
                    sum += data[j].close;
                }
                ma.push(sum / period);
            }

            return ma;
        }

        // 分析核心类
        class CryptoAnalyzer {
            constructor() {
                this.symbols = ['BTCUSDT', 'ETHUSDT'];
                this.intervals = ['10m', '30m', '1h']; // 分析的三个时间周期
                this.historicalData = {};
                this.currentSignals = {};

                // 初始化数据结构
                this.symbols.forEach(symbol => {
                    this.historicalData[symbol] = {};
                    this.currentSignals[symbol] = {};
                    this.intervals.forEach(interval => {
                        this.historicalData[symbol][interval] = [];
                        this.currentSignals[symbol][interval] = {};
                    });
                });
            }

            async startAnalysis() {
                // 显示加载状态
                document.getElementById('status').classList.remove('hidden');
                document.getElementById('start-analysis').disabled = true;

                try {
                    // 为所有交易对和所有时间间隔获取数据
                    await this.fetchDataForAllSymbols();

                    // 分析所有数据
                    for (const symbol of this.symbols) {
                        for (const interval of this.intervals) {
                            this.analyzeCurrentData(symbol, interval);
                        }
                    }

                    // 更新UI显示所有结果
                    this.updateAnalysisResults();

                    return { success: true };
                } catch (error) {
                    console.error("分析过程出错:", error);
                    alert("分析过程中出错: " + error.message);
                    return { success: false, error: error.message };
                } finally {
                    // 隐藏加载状态
                    document.getElementById('status').classList.add('hidden');
                    document.getElementById('start-analysis').disabled = false;
                }
            }

            async fetchDataForAllSymbols() {
                const fetchPromises = [];

                // 为每个交易对和每个时间间隔创建获取数据的Promise
                for (const symbol of this.symbols) {
                    for (const interval of this.intervals) {
                        fetchPromises.push(this.fetchAndProcessData(symbol, interval));
                    }
                }

                // 等待所有数据获取完成
                await Promise.all(fetchPromises);
            }

            async fetchAndProcessData(symbol, interval) {
                try {
                    // 根据不同的时间间隔设置不同的获取参数
                    const fetchInterval = interval === '10m' ? '5m' : interval;
                    const limit = fetchInterval === '5m' ? 600 : 300;

                    const url = `https://bnapi.bnlex.top/fapi/fapi/v1/klines?symbol=${symbol}&interval=${fetchInterval}&limit=${limit}`;
                    const response = await fetch(url);

                    if (!response.ok) throw new Error(`HTTP ${response.status}`);

                    const klineData = await response.json();
                    const formattedData = this.formatKlineData(klineData, interval);

                    // 存储格式化后的数据
                    this.historicalData[symbol][interval] = formattedData;
                    return true;
                } catch (error) {
                    console.error(`获取${symbol} ${interval}数据失败:`, error);
                    return false;
                }
            }

            formatKlineData(klineData, displayInterval) {
                const formatted = klineData.map(item => ({
                    time: Math.floor(item[0] / 1000),
                    open: parseFloat(item[1]),
                    high: parseFloat(item[2]),
                    low: parseFloat(item[3]),
                    close: parseFloat(item[4]),
                    volume: parseFloat(item[5]),
                    closeTime: item[6]
                }));

                // 如果是10m间隔，需要合并5m数据
                return displayInterval === '10m' ? this.convert5mTo10m(formatted) : formatted;
            }

            convert5mTo10m(data) {
                const merged = [];
                for (let i = 0; i < data.length - 1; i += 2) {
                    const candle1 = data[i];
                    const candle2 = data[i + 1];

                    merged.push({
                        time: candle1.time,
                        open: candle1.open,
                        high: Math.max(candle1.high, candle2.high),
                        low: Math.min(candle1.low, candle2.low),
                        close: candle2.close,
                        volume: candle1.volume + candle2.volume,
                        closeTime: candle2.closeTime
                    });
                }

                return merged.length > 0 ? merged : data;
            }

            analyzeCurrentData(symbol, interval) {
                const data = this.historicalData[symbol]?.[interval];
                if (!data || data.length < 50) return;

                const lastIndex = data.length - 1;
                const signals = this.calculateAllIndicators(data, interval);

                // 添加支撑阻力位计算
                signals.supports = this.getSupportResistance(data, signals.periods);

                // 添加成交量分析
                signals.volume = {
                    current: data[lastIndex].volume,
                    ma20: calculateMA(data.map(d => ({close: d.volume})), 20)[lastIndex],
                    trend: this.getTrend(data.map(d => d.volume), lastIndex)
                };

                // 生成预测
                signals.prediction = this.generatePrediction(signals);

                // 存储结果
                this.currentSignals[symbol][interval] = signals;
            }

            calculateAllIndicators(data, interval) {
                const lastIndex = data.length - 1;

                // 根据不同时间间隔设置不同的均线周期
                const getPeriods = () => {
                    switch(interval) {
                        case '10m':
                            return { maShort: 6, maMedium: 12, maLong: 24 };
                        case '30m':
                            return { maShort: 8, maMedium: 16, maLong: 32 };
                        case '1h':
                            return { maShort: 5, maMedium: 10, maLong: 20 };
                        default:
                            return { maShort: 5, maMedium: 10, maLong: 20 };
                    }
                };

                const periods = getPeriods();

                return {
                    price: data[lastIndex].close,
                    maShort: calculateMA(data, periods.maShort)[lastIndex],
                    maMedium: calculateMA(data, periods.maMedium)[lastIndex],
                    maLong: calculateMA(data, periods.maLong)[lastIndex],
                    maShortTrend: this.getTrend(calculateMA(data, periods.maShort), lastIndex),
                    maMediumTrend: this.getTrend(calculateMA(data, periods.maMedium), lastIndex),
                    maLongTrend: this.getTrend(calculateMA(data, periods.maLong), lastIndex),
                    rsi: calculateRSI(data, 14)[lastIndex],
                    rsiTrend: this.getTrend(calculateRSI(data, 14), lastIndex),
                    macdDiff: calculateMACD(data).dif[lastIndex] - calculateMACD(data).dea[lastIndex],
                    macdTrend: this.getMACDTrend(calculateMACD(data), lastIndex),
                    kdjCross: this.getKDJCross(calculateKDJ(data), lastIndex),
                    periods
                };
            }

            getSupportResistance(data, periods) {
                const lastIndex = data.length - 1;
                const currentPrice = data[lastIndex].close;
                const maMedium = calculateMA(data, periods.maMedium)[lastIndex];
                const bb = calculateBollingerBands(data, periods.maMedium);

                return {
                    support1: maMedium * 0.995,
                    resistance1: maMedium * 1.005,
                    support2: bb.lower[lastIndex],
                    resistance2: bb.upper[lastIndex],
                    support3: Math.floor(currentPrice / 10) * 10,
                    resistance3: Math.ceil(currentPrice / 10) * 10,
                    support4: this.getRecentLow(data, 24),
                    resistance4: this.getRecentHigh(data, 24)
                };
            }

            getRecentLow(data, periods) {
                return Math.min(...data.slice(-periods).map(d => d.low));
            }

            getRecentHigh(data, periods) {
                return Math.max(...data.slice(-periods).map(d => d.high));
            }

            generatePrediction(signals) {
                const trendSignal = this.detectTrend(signals);
                const reversalSignal = this.detectReversal(signals);

                return this.combineSignals(trendSignal, reversalSignal, signals);
            }

            detectTrend(signals) {
                const maUp = signals.maShortTrend === 'up' && signals.maMediumTrend === 'up';
                const maDown = signals.maShortTrend === 'down' && signals.maMediumTrend === 'down';

                const macdUp = ['crossUp', 'strongUp'].includes(signals.macdTrend);
                const macdDown = ['crossDown', 'strongDown'].includes(signals.macdTrend);

                const kdjUp = signals.kdjCross === 'goldenCross';
                const kdjDown = signals.kdjCross === 'deathCross';

                const upConditions = (maUp || macdUp) && (kdjUp || signals.rsi < 70);
                const downConditions = (maDown || macdDown) && (kdjDown || signals.rsi > 30);

                if (upConditions) {
                    return { direction: 'up', confidence: 0.7, type: 'trend' };
                } else if (downConditions) {
                    return { direction: 'down', confidence: 0.7, type: 'trend' };
                }

                return { direction: 'neutral', confidence: 0.5, type: 'trend' };
            }

            detectReversal(signals) {
                const extremeRsi = signals.rsi > 70 || signals.rsi < 30;
                const volumeSpike = signals.volume.current > signals.volume.ma20 * 1.5;

                if (signals.rsi > 70 && signals.rsiTrend === 'down' &&
                    signals.macdTrend === 'crossDown' && volumeSpike) {
                    return { direction: 'down', confidence: 0.65, type: 'reversal' };
                }

                if (signals.rsi < 30 && signals.rsiTrend === 'up' &&
                    signals.macdTrend === 'crossUp' && volumeSpike) {
                    return { direction: 'up', confidence: 0.65, type: 'reversal' };
                }

                return null;
            }

            combineSignals(trend, reversal, signals) {
                if (trend.confidence >= 0.7) return trend;
                if (reversal && this.volumeConfirms(reversal, signals)) {
                    return reversal;
                }
                return trend;
            }

            volumeConfirms(signal, signals) {
                const volumeTrendMatch = signal.direction === 'up' ?
                    signals.volume.trend === 'up' : signals.volume.trend === 'down';
                return volumeTrendMatch && signals.volume.current > signals.volume.ma20;
            }

            getTrend(values, index) {
                if (index < 2 || !values[index] || !values[index-1]) return 'neutral';
                return values[index] > values[index-1] ? 'up' : 'down';
            }

            getMACDTrend(macd, index) {
                if (index < 2 || !macd.dif[index] || !macd.dea[index]) return 'neutral';

                const dif = macd.dif[index], dea = macd.dea[index];
                const prevDif = macd.dif[index-1], prevDea = macd.dea[index-1];

                if (dif > dea && dif > prevDif && dea > prevDea) return 'strongUp';
                if (dif < dea && dif < prevDif && dea < prevDea) return 'strongDown';
                if (dif > dea && prevDif < prevDea) return 'crossUp';
                if (dif < dea && prevDif > prevDea) return 'crossDown';
                return 'neutral';
            }

            getKDJCross(kdj, index) {
                if (index < 2 || !kdj.k[index] || !kdj.d[index]) return 'neutral';

                const k = kdj.k[index], d = kdj.d[index];
                const prevK = kdj.k[index-1], prevD = kdj.d[index-1];

                if (k > d && prevK < prevD) return 'goldenCross';
                if (k < d && prevK > prevD) return 'deathCross';
                if (k > d) return 'above';
                if (k < d) return 'below';
                return 'neutral';
            }

            updateAnalysisResults() {
                // 为每个交易对创建分析卡片
                for (const symbol of this.symbols) {
                    const container = document.getElementById(`${symbol.toLowerCase().replace('usdt', '')}-container`);
                    container.innerHTML = ''; // 清空现有内容

                    // 为每个时间间隔创建卡片
                    for (const interval of this.intervals) {
                        const signals = this.currentSignals[symbol][interval];
                        if (signals && Object.keys(signals).length > 0) {
                            this.createAnalysisCard(container, symbol, signals, interval);
                        }
                    }
                }
            }

            createAnalysisCard(container, symbol, signals, interval) {
                const direction = signals.prediction.direction;
                const confidence = (signals.prediction.confidence * 100).toFixed(1);
                const rsiValue = signals.rsi ? signals.rsi.toFixed(2) : 'N/A';
                const rsiLevel = this.getRSILevel(signals.rsi);
                const recommendation = this.getRecommendation(direction, signals.prediction.confidence);

                // 根据趋势方向设置颜色和图标
                const trendColor = direction === 'up' ? 'text-success' : direction === 'down' ? 'text-danger' : 'text-dark-2';
                const trendIcon = direction === 'up' ? 'fa-arrow-up' : direction === 'down' ? 'fa-arrow-down' : 'fa-minus';
                const trendText = direction === 'up' ? '看涨' : direction === 'down' ? '看跌' : '横盘';

                // 创建卡片元素
                const card = document.createElement('div');
                card.className = 'bg-white rounded-lg p-6 card-shadow analysis-card';
                card.innerHTML = `
                    <div class="flex justify-between items-start mb-4">
                        <h3 class="text-lg font-semibold">${symbol}</h3>
                        <span class="bg-light-1 text-dark-2 text-sm py-1 px-3 rounded-full">${this.formatInterval(interval)}</span>
                    </div>

                    <div class="mb-4">
                        <div class="text-2xl font-bold mb-1">$${signals.price.toFixed(2)}</div>
                        <div class="${trendColor} font-medium flex items-center">
                            <i class="fa ${trendIcon} mr-1"></i>${trendText} (${confidence}%)
                        </div>
                    </div>

                    <div class="grid grid-cols-2 gap-4 mb-4">
                        <div class="bg-light-1 rounded-lg p-3">
                            <div class="text-sm text-dark-2 mb-1">RSI指数</div>
                            <div class="font-medium ${this.getRSIColorClass(signals.rsi)}">${rsiValue} (${rsiLevel})</div>
                        </div>
                        <div class="bg-light-1 rounded-lg p-3">
                            <div class="text-sm text-dark-2 mb-1">MACD趋势</div>
                            <div class="font-medium">${this.formatMacdTrend(signals.macdTrend)}</div>
                        </div>
                    </div>

                    <div class="mb-4">
                        <div class="text-sm text-dark-2 mb-1">操作建议</div>
                        <div class="font-medium ${this.getRecommendationColor(recommendation)}">${recommendation}</div>
                    </div>

                    <div class="text-sm text-dark-2 space-y-1">
                        <div><span class="font-medium">支撑位:</span> ${signals.supports.support1.toFixed(2)}</div>
                        <div><span class="font-medium">阻力位:</span> ${signals.supports.resistance1.toFixed(2)}</div>
                    </div>
                `;

                container.appendChild(card);
            }

            formatInterval(interval) {
                switch(interval) {
                    case '10m': return '10分钟';
                    case '30m': return '30分钟';
                    case '1h': return '60分钟';
                    default: return interval;
                }
            }

            formatMacdTrend(trend) {
                const trendMap = {
                    'strongUp': '强势上涨',
                    'strongDown': '强势下跌',
                    'crossUp': '金叉',
                    'crossDown': '死叉',
                    'neutral': '横盘'
                };
                return trendMap[trend] || trend;
            }

            getRSILevel(rsiValue) {
                if (!rsiValue) return 'N/A';
                if (rsiValue > 80) return '极端超买';
                if (rsiValue > 70) return '超买';
                if (rsiValue < 20) return '极端超卖';
                if (rsiValue < 30) return '超卖';
                if (rsiValue > 60) return '强势';
                if (rsiValue < 40) return '弱势';
                return '中性';
            }

            getRSIColorClass(rsiValue) {
                if (!rsiValue) return '';
                if (rsiValue > 80) return 'text-danger';
                if (rsiValue > 70) return 'text-danger/80';
                if (rsiValue < 20) return 'text-success';
                if (rsiValue < 30) return 'text-success/80';
                if (rsiValue > 60) return 'text-success/70';
                if (rsiValue < 40) return 'text-danger/70';
                return 'text-dark-2';
            }

            getRecommendationColor(recommendation) {
                if (recommendation.includes('看涨')) return 'text-success';
                if (recommendation.includes('看跌')) return 'text-danger';
                return 'text-warning';
            }

            getRecommendation(direction, confidence) {
                if (direction === 'up' && confidence > 0.7) return '强烈建议看涨';
                if (direction === 'up' && confidence > 0.5) return '建议看涨';
                if (direction === 'down' && confidence > 0.7) return '强烈建议看跌';
                if (direction === 'down' && confidence > 0.5) return '建议看跌';
                return '观望';
            }
        }

        // 全局分析器实例
        let cryptoAnalyzer = null;

        // 启动分析函数
        async function startAnalysis() {
            if (!cryptoAnalyzer) {
                cryptoAnalyzer = new CryptoAnalyzer();
            }
            await cryptoAnalyzer.startAnalysis();
        }
    </script>
</body>
</html>